import re
import networkx as nx
from configparser import ConfigParser


def read_graph():
    config = ConfigParser()
    config.read('./master/settings', encoding='utf-8')
    if config['name_type']['type'] == '1':
        file = open('./dfa/table_dfa_graph', 'r+')
    elif config['name_type']['type'] == '2':
        file = open('./dfa/index_dfa_graph', 'r+')
    graph = nx.DiGraph()
    for line in file.readlines():
        edge_data = line.strip('\n').strip('\t').split(' ')
        node_1 = int(edge_data[0])
        node_2 = int(edge_data[1])
        names = edge_data[2:]
        graph.add_edge(node_1, node_2, names=names)
    # print(graph.nodes())
    # print(graph.edges())
    file.close()
    return graph


read_graph()
